package cre.redis.thread;

/**
 * Created by CreGu on 2016/7/1.
 */
public class Bag {

    private int count = 10;
    private RedisLock redisLock = new RedisLock();

    public synchronized boolean get() {
        if (count > 0) {
            count--;
            return true;
        } else return false;
    }

    public boolean get2() {
        String name = "bag";
        if (redisLock.lock(name, 10, 10, 10)) {
            if (count > 0) {
                count--;
                return true;
            } else return false;
        } else return false;

    }

    public static void main(String[] args) {
        Bag bag = new Bag();
        for (int i = 0; i < 20; i++) {
            System.out.println(i + ": " + bag.get2());
        }
    }
}
